package com.flyou.ccnucenter.ui.activity.henuBeside;

import android.content.Intent;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.e1858.myalertview.AlertView;
import com.e1858.myalertview.OnItemClickListener;
import com.flyou.ccnucenter.R;
import com.flyou.ccnucenter.adapter.HenuBesideMapAdapter;
import com.flyou.ccnucenter.domain.HenuBesideMapItem;
import com.flyou.ccnucenter.ui.activity.BaseActivity1;
import com.flyou.ccnucenter.ui.activity.henuBeside.anonymousLove.AnonymousLoveListActivity;
import com.flyou.ccnucenter.ui.activity.henuBeside.lostFind.LostFoundActivity;
import com.flyou.ccnucenter.ui.activity.henuBeside.map.MapListActivity;
import com.flyou.ccnucenter.ui.activity.henuBeside.note.NoteListActivity;
import com.flyou.ccnucenter.utils.LoginUtils;
import com.mingle.entity.MenuEntity;
import com.mingle.sweetpick.BlurEffect;
import com.mingle.sweetpick.RecyclerViewDelegate;
import com.mingle.sweetpick.SweetSheet;

import java.util.ArrayList;
import java.util.List;

public class HenuBesideActivity extends BaseActivity1 implements View.OnClickListener, OnItemClickListener, AdapterView.OnItemClickListener {
    private RelativeLayout mTitlebarRlBack;
    private TextView mTitlebarTvTitle;
    private AlertView mAlertView;
    private ImageView lostFound;
    private ImageView saying;
    private ImageView love;
    private ImageView note;
    private ImageView score;
    private GridView gridMap;
    private List<HenuBesideMapItem> henuBesideMapItems;
    private RelativeLayout rl;
    private SweetSheet mSweetSheet;



    @Override
    protected void initView() {
        setContentView(R.layout.activity_henu_beside);
        rl = (RelativeLayout) findViewById(R.id.rl);
        mTitlebarRlBack = (RelativeLayout) findViewById(R.id.titlebar_rl_back);
        mTitlebarTvTitle = (TextView) findViewById(R.id.titlebar_tv_title);
        lostFound = (ImageView) findViewById(R.id.henu_beside_lostfound);
        saying = (ImageView) findViewById(R.id.henu_beside_saying);
        love = (ImageView) findViewById(R.id.henu_beside_love);
        note = (ImageView) findViewById(R.id.henu_beside_note);
        score = (ImageView) findViewById(R.id.henu_beside_score);
        gridMap = (GridView) findViewById(R.id.gv_map);
        setupRecyclerView();

    }

    @Override
    protected void initDate() {

        mTitlebarTvTitle.setText("Star周边");
        henuBesideMapItems = new ArrayList<>();
        henuBesideMapItems.add(new HenuBesideMapItem("美食", R.drawable.dinner));
        henuBesideMapItems.add(new HenuBesideMapItem("超市", R.drawable.mall));
        henuBesideMapItems.add(new HenuBesideMapItem("KTV", R.drawable.ktv));
        henuBesideMapItems.add(new HenuBesideMapItem("美妆", R.drawable.beauty));
        henuBesideMapItems.add(new HenuBesideMapItem("酒店", R.drawable.hotel));
        henuBesideMapItems.add(new HenuBesideMapItem("ATM", R.drawable.atm));
        henuBesideMapItems.add(new HenuBesideMapItem("电影", R.drawable.cinema));
        henuBesideMapItems.add(new HenuBesideMapItem("网吧", R.drawable.cybercafe));
    }

    @Override
    protected void setListener() {
        mTitlebarRlBack.setOnClickListener(this);
        lostFound.setOnClickListener(this);
        love.setOnClickListener(this);
        saying.setOnClickListener(this);
        note.setOnClickListener(this);
        score.setOnClickListener(this);
        HenuBesideMapAdapter henuBesideMapAdapter = new HenuBesideMapAdapter(HenuBesideActivity.this, henuBesideMapItems);
        gridMap.setAdapter(henuBesideMapAdapter);
        gridMap.setOnItemClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.titlebar_rl_back:
                finish();
                break;

            case R.id.henu_beside_lostfound:

                Intent lostFoundIntent = new Intent(HenuBesideActivity.this, LostFoundActivity.class);
                    startActivity(lostFoundIntent);
                break;
            case R.id.henu_beside_love:

                Intent AnonymousLoveIntent =new Intent(HenuBesideActivity.this, AnonymousLoveListActivity.class);
                startActivity(AnonymousLoveIntent);


                break;
            case R.id.henu_beside_saying:
                if (LoginUtils.isLogined(HenuBesideActivity.this)) {
                Intent smartChatIntent =new Intent(HenuBesideActivity.this,SmartChartActivity.class);
                    startActivity(smartChatIntent);

                } else {
                    LoginUtils.Login(HenuBesideActivity.this);
                }


                break;
            case R.id.henu_beside_score:
                mAlertView = new AlertView("选择查询的种类", null, "取消", null, new String[]{"英语四六级", "普通话水平测试", "计算机等级考试"}, this, AlertView.Style.ActionSheet, this);
                mAlertView.show();
                break;
            case R.id.henu_beside_note:
                if (LoginUtils.isLogined(HenuBesideActivity.this)) {
                    Intent noteIntent = new Intent(HenuBesideActivity.this, NoteListActivity.class);
                    startActivity(noteIntent);
                } else {
                    LoginUtils.Login(HenuBesideActivity.this);
                }


                break;

        }

    }

    @Override
    public void onItemClick(Object o, int position) {
        Intent intent = new Intent(HenuBesideActivity.this, ScoreActivity.class);
        switch (position) {

            case 0:
                intent.putExtra("score_type", 0);
                startActivity(intent);
                break;
            case 1:
                intent.putExtra("score_type", 1);
                startActivity(intent);
                break;
            case 2:
                intent.putExtra("score_type", 2);
                startActivity(intent);
                break;

        }


    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
            if (mAlertView != null && mAlertView.isShowing()) {
                mAlertView.dismiss();
                return false;
            }
        }

        return super.onKeyDown(keyCode, event);

    }


    private void setupRecyclerView() {

        ArrayList<MenuEntity> list = new ArrayList<>();
        //添加假数据
        MenuEntity menuEntity1 = new MenuEntity();
        menuEntity1.iconId = R.drawable.ic_found_note_icon;
        menuEntity1.title = "code";
        MenuEntity menuEntity = new MenuEntity();
        menuEntity.iconId = R.drawable.ic_found_note_icon;
        menuEntity.title = "QQ";
        list.add(menuEntity1);
        list.add(menuEntity);
        list.add(menuEntity);
        list.add(menuEntity);
        list.add(menuEntity);
        list.add(menuEntity);
        list.add(menuEntity);
        list.add(menuEntity);
        list.add(menuEntity);
        list.add(menuEntity);
        list.add(menuEntity);
        list.add(menuEntity);
        list.add(menuEntity);
        // SweetSheet 控件,根据 rl 确认位置
        mSweetSheet = new SweetSheet(rl);

        //设置数据源 (数据源支持设置 list 数组,也支持从菜单中获取)
        mSweetSheet.setMenuList(list);
        //根据设置不同的 Delegate 来显示不同的风格.
        mSweetSheet.setDelegate(new RecyclerViewDelegate(true));
        //根据设置不同Effect 来显示背景效果BlurEffect:模糊效果.DimEffect 变暗效果
        mSweetSheet.setBackgroundEffect(new BlurEffect(8));
        //设置点击事件
        mSweetSheet.setOnMenuItemClickListener(new SweetSheet.OnMenuItemClickListener() {
            @Override
            public boolean onItemClick(int position, MenuEntity menuEntity1) {

                //根据返回值, true 会关闭 SweetSheet ,false 则不会.
                Toast.makeText(HenuBesideActivity.this, menuEntity1.title + "  " + position, Toast.LENGTH_SHORT).show();
                return true;
            }
        });


    }


    @Override
    public void onBackPressed() {

        if (mSweetSheet.isShow()) {
            mSweetSheet.dismiss();
        } else {
            super.onBackPressed();
        }

    }

    /*
    *点击进入各个板块
    * */
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        String keyWord = henuBesideMapItems.get(position).getTitle();
        Intent intent=new Intent(HenuBesideActivity.this, MapListActivity.class);
        intent.putExtra("keyWord",keyWord);
        startActivity(intent);

    }
}
